package com.zzz.dao;

import com.zzz.entity.Permission;
import com.zzz.entity.User;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Chunsheng.Zhang
 * @date 2021/5/11 9:45
 * @description : TODO
 */
@Component
public class UserDao {

    private static Set<User> userSet = new HashSet<>();


    static {
        List<Permission> permissions1 = new ArrayList<>();
        permissions1.add(new Permission().setCode("user:sel"));
        permissions1.add(new Permission().setCode("menu:sel"));

        List<Permission> permissions2 = new ArrayList<>();
        permissions2.add(new Permission().setCode("menu:sel"));

        User user1 = new User()
                        .setUsername("zs")
                        .setPassword("$2a$10$VmogNL2yPi.8AKS.XJvmDOYdzIETzJEu9AurdVaeEB9CyZecxhb3W")
                        .setPermissionList(permissions1);
        User user2 = new User()
                        .setUsername("ls")
                        .setPassword("$2a$10$p26gDq71L3Wvpo41uFjac.UDh25bv3V60hbBFYrhcyAi7M.vhE60m")
                        .setPermissionList(permissions2);

        userSet.add(user1);
        userSet.add(user2);
    }



    public User selByUsername(String username){
        User result = null;
        for (User user : userSet) {
            if(username.equals(user.getUsername())){
                result = user;
                break;
            }
        }
        return result;
    }
}
